package io.jt808.proto.req;

import io.norland.annotations.Proto;
import io.norland.buffer.AutoBuffer;
import io.norland.proto.IProto;
import lombok.Data;

/**
 * 终端通用应答
 */
@Proto("0001")
@Data
public class JT0001 implements IProto {
    /**
     * 应答消息流水号
     */
    private int responseMessageSerialNo;
    /**
     * 应答消息ID
     */

    private int responseMessageId;
    /**
     * 应答结果，0：成功/确认；1：失败；2：消息有误；3：不支持
     */
    private byte responseResult;

    public byte[] writeToBytes() {
        AutoBuffer buff = new AutoBuffer();
        buff.writeShort(responseMessageSerialNo);
        buff.writeShort(responseMessageId);
        buff.writeByte(responseResult);
        return buff.array();

    }

    public void readFromBuf(AutoBuffer buff) {
        responseMessageSerialNo = buff.readUnsignedShort();
        responseMessageId = buff.readUnsignedShort();
        responseResult = buff.readByte();
    }

    public String getResult() {
        switch (responseResult) {
            case 0:
                return "success";
            case 1:
                return "fail";
            default://3
                return "UN support";
        }
    }

}